<template>
  <div v-if="visible" class="i18n-modal-mask">
    <div class="i18n-modal ">
      <div class="header   border-b-gray-300 border-b">
        <h3 class="pl-3 pb-2 font-bold">新建国际化信息</h3>
        <button @click="handleClose" class="close-btn pr-3 pb-2">×</button>
      </div>
      <div>
        <div class="I18-item">
          <label class="required">国际化标识：</label>
          <input
            v-model="form.code"
            placeholder="国际化信息的标识"
            class="input-field "
          />
        </div>
        <div class="I18-item">
          <label>语言文本：</label>
          <div class="language-fields">
            <div class="language-item">
              <input value="zh-CN" disabled class="lang-code" />
              <input
                v-model="form.languageTexts[0].message"
                placeholder="文本值"
                class="text-input"
              />
              <button class="deletebtn" disabled>－</button>
            </div>
            <div class="language-item">
              <input value="en-US" disabled class="lang-code" />
              <input
                v-model="form.languageTexts[1].message"
                placeholder="文本值"
                class="text-input"
              />
              <button class="deletebtn" disabled>－</button>
            </div>
            <button @click="addLanguageField" class="addbtn">
              + Add field
            </button>
          </div>
        </div>
        <div class="I18-item flex items-center">
          <label>备注：</label>
          <textarea
            v-model="form.remarks"
            placeholder="请输入备注内容"
            class="remark-textarea"
          ></textarea>
        </div>
      </div>
      <div class="footer">
        <button @click="handleClose" class="cancel-btn">取消</button>
        <button @click="handleConfirm" class="confirm-btn">确定</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AddI18n',
  emits: ['update:visible', 'confirm'],
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        code: '',
        languageTexts: [
          { languageTag: 'zh-CN', message: '' },
          { languageTag: 'en-US', message: '' }
        ], // 包含语言标签和文本的对象数组
        remarks: ''
      }
    };
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false);
      this.resetForm();
    },
    handleConfirm() {
      this.$emit('confirm', { ...this.form });
      this.handleClose();
    },
    addLanguageField() {
      // 实际场景可扩展新增语言字段逻辑
      alert('新增语言字段功能（可根据需求扩展）');
    },
    resetForm() {
      this.form = {
        code: '',
        languageTexts: [
          { lang: 'zh-CN', message: '' },
          { lang: 'en-US', message: '' }
        ], // 包含语言标签和文本的对象数组
        remarks: ''
      };
    }
  }
};
</script>

<style scoped>
.i18n-modal-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.i18n-modal {
  background: #fff;
  border-radius: 4px;
  width: 500px;
  padding: 20px 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.header h3 {
  margin: 0;
  font-size: 18px;
}

.close-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
}

.I18-item {
  margin-bottom: 16px;
  margin-left: 15px;
}

label {
  display: inline-block;
  width: 100px;
  text-align: right;
  margin-right: 10px;
  font-size: 14px;
}

.required::before {
  content: '*';
  color: red;
  margin-right: 4px;
}


.input-field,
.text-input,
.remark-textarea {
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px;
  font-size: 14px;
}

/* 设置placeholder文字颜色为浅灰色 */
.input-field::placeholder,
.text-input::placeholder,
.remark-textarea::placeholder {
  color: #aaa;
}

.input-field {
  width: 300px;
}

.language-fields {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin-left: 110px;
}

.language-item {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.lang-code {
  width: 60px;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 6px;
  margin-right: 8px;
  background: #f5f5f5;
}

.text-input {
  width: 220px;
  margin-right: 8px;
}

.deletebtn {
  width: 30px;
  height: 30px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 100%;
  cursor: pointer;
}

.addbtn {
  width: 300px;
  margin-top: 8px;
  background: transparent;
  border: 1px dashed #ddd;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
}

.remark-textarea {
  width: 300px;
  height: 80px;
  resize: vertical;
}

.footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.cancel-btn,
.confirm-btn {
  padding: 8px 16px;
  margin-right: 15px;
  border-radius: 4px;
  cursor: pointer;
}

.cancel-btn {
  background: #fff;
  border: 1px solid #ddd;
}

.confirm-btn {
  background: #719de9;
  border: none;
  color: #fff;
}
</style>